package com.lb.statck.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import javax.servlet.http.HttpServletRequest;

public class HttpUtils {
    /**
     * 从HttpServletRequest中读取请求体数据
     *
     * @param request 请求对象
     * @return 请求体数据
     * @throws IOException 如果读取过程中发生异常
     */
    public static String readData(HttpServletRequest request) throws IOException {
        StringBuilder sb = new StringBuilder();
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8))) {
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        }
        return sb.toString();
    }
}
